import 'package:flutter/material.dart';
import 'package:fzcgx_app/common/adapter_utils.dart';
import 'package:fzcgx_app/ui/my/factory/model/factory_product_category_model.dart';

class CustomChipWidget extends StatefulWidget {
  final Color borderColor;
  final Color textColor;
  final Color selectBorderColor;
  final Color selectTextColor;
  final Color backgroundColor;
  final Color selectBackgroundColor;
  final FactoryProductCategoryModel model;
  final bool showBorder;
  final Function onTap;
  CustomChipWidget({
    Key key,
    this.borderColor = const Color(0xff99A2AD),
    this.textColor = const Color(0xff606B79),
    this.selectTextColor = const Color(0xff15A1FF),
    this.selectBorderColor = const Color(0xff15A1FF),
    this.backgroundColor = Colors.white,
    this.selectBackgroundColor=Colors.white,
    this.model,
    this.showBorder = true,
    this.onTap,
  }) : super(key: key);

  @override
  _CustomChipWidgetState createState() => _CustomChipWidgetState();
}

class _CustomChipWidgetState extends State<CustomChipWidget> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        widget.onTap(widget.model);
      },
      child: Container(
        padding: EdgeInsets.symmetric(
            horizontal: AdapterUtils.getWidth(15),
            vertical: AdapterUtils.getHeight(8)),
        decoration: BoxDecoration(
            color:_getBackgroundColor(),
            border: widget.showBorder
                ? Border.all(
                    color: widget.model.check
                        ? widget.selectBorderColor
                        : widget.borderColor,
                    width: 1)
                : Border(),
            borderRadius: BorderRadius.all(Radius.circular(17.5))),
        child: Text(
          widget.model.name,
          style: TextStyle(
            fontSize: AdapterUtils.getSp(14),
            color: widget.model.check
                ? widget.selectTextColor
                : widget.textColor,
            fontWeight: FontWeight.w500,
          ),
        ),
      ),
    );
  }
  Color _getBackgroundColor(){
    if(widget.showBorder){
      return widget.backgroundColor;
    }else{
if(widget.model.check){
         return widget.selectBackgroundColor;
      }else{
         return widget.backgroundColor;
      }
    }
  }
}
